package com.resou.reader.view;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.resou.reader.R;

/**
 * Created by ${Garrett} on 2018/11/2.
 * Contact me krouky@outlook.com
 */
public class FragmentLoading extends Fragment {

    private FragmentManager mFragmentManager;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return LayoutInflater.from(getContext()).inflate(R.layout.fragment_loading_layout, container, false);
    }

    public void show(int resId, @NonNull FragmentManager manager) {
        mFragmentManager = manager;
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.add(resId, this);
        transaction.commitAllowingStateLoss();
    }

    public void dismiss() {
        if (mFragmentManager != null && isAdded() && !isDetached()) {
            mFragmentManager.beginTransaction().remove(this).commitAllowingStateLoss();
        }
    }

}
